<?php global $ubi;?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>TÙM LUM site</title>
        
		<link href="include/css/style.css" media="screen" rel="stylesheet" type="text/css" />
		<link href="include/css/styles.css" type="text/css" media="all" rel="stylesheet" id="contact-form-7-css" />
        <link href="include/css/site.css" media="screen" type="text/css" rel="stylesheet" />
		<link href="include/css/jquery.wysiwyg.css" type="text/css" rel="stylesheet" />
		<link href="include/css/style-dropdownlist.css" type="text/css" rel="stylesheet" />
		
		<script language="javascript" src="include/script/jquery-1.4.4.min.js" type="text/javascript"></script>
		<script language="javascript" type="text/javascript" src="include/script/script.js"></script>
		<script language="javascript" type="text/javascript" src="include/script/jquery.wysiwyg.js"></script>
		<script language="javascript" type="text/javascript" src="include/script/jquery.combobox.js"></script>
		
		<script type="text/javascript" language="javascript">
			$(document).ready(function(){
				$('#randomItemProvider').load('index.php?load&view=randomItemProvider');
				$('#blockSignIn').load('index.php?load&view=blockSignIn');
				$('#blockSearch').load('index.php?load&view=blockSearch');
				$('#blockMembers').load('index.php?load&view=blockMembers');
				$('#blockNewestPosts').load('index.php?load&view=blockNewestPosts');
				$('#mainMenu').load('index.php?load&view=menu&location=items');
				$('#footer').load('index.php?load&view=footer');
				$('#item_input').wysiwyg();
			
				$('#lnkAddItemCategory').click(function() {
					var val = $('#selCatItem2 option:selected').val();
	
					var arrCat = [];
					$('input[class=hiddenCatItemID]').each(function(index) {
						arrCat.push($(this).val());		    
					});
					var ok = true;
					for (var i = 0; i < arrCat.length; i++) {
						if (arrCat[i] == val) {
							ok = false;							
							break;
						}
					}

					if (ok) {
						$('#messCat').hide();
						var newRow = '<tr><td>' + $('#selCatItem1 option:selected').html() + '</td>' 
										+ '<td>' + $('#selCatItem2 option:selected').html() + '</td>' 
										+ '<td>' + '<input type="button" value="Xóa" onclick="$.removeCat(this)"></td>'
										+ '<td><input type="hidden" class="hiddenCatItemID" value="' + val + '" /></td>' 
									+'</tr>';
						$('#tblCatItem tr:last').after(newRow);
						var url = 'index.php?input&action=getCategoryItemQuestion';
						$.post(url, {'cat' : val}, function(data){
							var str = '<div id="cat' + val + '">' + $.getStringFromXMLQuestions(data) + '</div>';							
							$('#blockDanhGia').append(str);							
						});
					} else {
						$('#messCat').html('Phân loại này đã được chọn. Bạn hãy chọn một phân loại khác !!!');
						$('#messCat').show();
					}
				});

				$('#selCatItem1').change(function() {
					pid = $('#selCatItem1 option:selected').val();
					url = 'index.php?input&action=getCategoryItem';

					$.doPostGetCategoryList(pid, '#selCatItem2', url);				
				});

				$('#btnSearchProvider').click(function() {
					var text = $('#frmSearchProvider input[name=txtProvider]').val();		
					var url = 'index.php?provider&action=searchProvider';
					$.post(url, {'searchProvider' : text}, function(data){
						if (data != null && data != '') {
							str = $.getStringFromXMLProviders(data);			
							$('#searchResult').html(str);				
						} else {
							$('#searchResult').html('<span class="red">Không tìm thấy địa điểm này !!!</span>'); 
						}
						return false;
					});					
				});

				$('#frmInputItem').submit(function() {
					var str = '';
					if ($('#frmInputItem [name=txtItemName]').val() == '') {			
						str += 'Bạn chưa nhập tên item\n';
					}
					if ($('#frmInputItem [name=txtNumber]').val() == '') {
						str += 'Bạn chưa nhập số nhà\n';
					}
					if ($('#frmInputItem [name=txtStreet]').val() == '') {
						str += 'Bạn chưa nhập số nhà\n';
					}				
	
					if (str != '') {
						return false;
					}	
	
					var str = '';
					$('input[class=hiddenCatItemID]').each(function(index) {
						str += ' ' + $(this).val();		    
					});		
					$('input[name=categoryItemList][type=hidden]').val(str);

					var answerList = '';
					$('#frmUpdateItem input[type=radio]').each(function(index) {
						if ($(this).attr('checked')) {
							answerList += $(this).val() + ' ';
						}		    
					});
					$('input[name=answerList]').val(answerList);
					
					return true;
				});

				var arrUnits = new Array();
				<?php
					foreach ($ubi['ITEM']['UNITS'] as $unit) {
				?>
						arrUnits.push('<?php echo $unit?>');
				<?php 		
					} 
				?>
				$('#selUnit').combobox(arrUnits);

				<?php
					if (array_key_exists('providerId', $getVars)) {
				?>
						var text = <?php echo $getVars['providerId'] ?>;
						var url = 'index.php?provider&action=searchProvider';
						$.post(url, {'searchProvider' : text}, function(data){
							if (data != null && data != '') {
								str = $.getStringFromXMLProviders(data);			
								$('#searchResult').html(str);				
							} else {
								$('#searchResult').html('<span class="red">Không tìm thấy địa điểm này !!!</span>'); 
							}
						});
				<?php 		
					} 
				?>
			});

			$.extend({
				removeCat:function(tag) {
					$.removeRow(tag);
					var val = $(tag).parent().parent().find('input[type=hidden]').val();
					$('#cat' + val).remove();
				}
			});
		</script>
	</head>
    
    <body id="cookoffboard" class="home blog">
		<div id="corners">			
			<div class="header" id="main-head">
				<div id="hdr-info">
                	<div style="float:left">
                        <img id="logo" src="include/imgs/logo4.png" alt="The Cook-Off Board" width="235px" />
                        <p id="desc">Tùm Lum, Tả Pí Lù, chia sẻ tất cả ở đây</p>
                    </div>
                    <div class="nav">
                        <div id="mainMenu"></div>
                        <div style="clear:both"></div>
                    </div>
				</div>          
			</div> <!--end header-->
            
			<div class="polaroids">
            	<div class="marginBoxPicCollection" id="randomItemProvider"></div>
			</div> <!--end polaris-->
            
            <div id="container">
				<hr />
                <div class="left">
                    <div class="section" id="content">
                        <form action='index.php?input&action=inputItem'	method='post' enctype='multipart/form-data' id='frmInputItem'>
							<fieldset class="form">
						    	<ul class="frm">
						        	<li class="input">
						            	<label for="name">Tên hàng hóa <span class="red">*</span></label>
						                <input type="text" class="txt_full" name="txtItem" />
						            </li>
						            <li class="input">
						            	<label for="mota">Mô Tả <span class="red">*</span></label>
						                <br />
						                <textarea id="item_input" class="textarea_input" rows="5" cols="60" name="txtItemDes"></textarea>
									</li>
						            <li class="input">
						            	<label for="donvi">Đơn Vị</label>
										<input id="selUnit" name="selUnit" type="text" />
									</li>               
						           	<li class="input">
						           		<label for="phanloai">Phân Loại</label>
						                <input type="hidden" name="categoryItemList" />
						                <div style="display:inline-block">                	
						                	<table id="tblCatItem">
						                		<tr>
						                			<td colspan="3">
						                				<span class="red" id="messCat"></span>
						                			</td>
						                		</tr>
						                    	<tr>
						                        	<td>
						                                <select name="selCatItem1" id="selCatItem1">
						                                	<?php
						                                		
						                                		$catItem =  $arrCatItem1[0];
						                                	?>
						                                	<option selected="selected" value="<?php echo $catItem->getCategoryID();?>"><?php echo $catItem->getCategory();?></option>
						                                	<?php                 
						                                	    for ($i = 1; $i < count($arrCatItem1); $i++) {
						                                			$catItem = $arrCatItem1[$i];                                	
						                                	?>
						                                	<option value="<?php echo $catItem->getCategoryID();?>"><?php echo $catItem->getCategory();?></option>
						                                	<?php 		
						                                		} 
						                                	?>	
						                                </select>
						                            </td>
						                            <td>
						                                <select name="selCatItem2" id="selCatItem2">
						                                    <?php
						                                		$catItem =  $arrCatItem2[0];
						                                	?>
						                                	<option selected="selected" value="<?php echo $catItem->getCategoryID();?>"><?php echo $catItem->getCategory();?></option>
						                                	<?php                 
						                                	    for ($i = 1; $i < count($arrCatItem2); $i++) {
						                                			$catItem = $arrCatItem2[$i];                                	
						                                	?>
						                                	<option value="<?php echo $catItem->getCategoryID();?>"><?php echo $catItem->getCategory();?></option>
						                                	<?php 		
						                                		} 
						                                	?>                            	
							                            </select>
						                            </td>
						                            <td><input type="button" id="lnkAddItemCategory" value="Thêm" /></td>                            
												</tr>                                		                                		
											</table>
							            </div>
									</li>     
						            <li class="input">            	
						            	<label for="giasan">Giá Từ</label>
						            	<input type="text" class="txt_short" name="txtPriceFrom" />	           	
						            </li>
						            <li class="input">
						            	<label for="giatran">Giá Đến</label>
						            	<input type="text" class="txt_short" name="txtPriceTo" />
						            </li>
						            <li class="input">
						            	<label for="hinhanh">Hình Ảnh</label>
										<input type="file" name="imgItem" />
						            </li>     
									
						            <li class="input">
						            	<label>Địa Điểm</label>
						            	<div style="display:inline-block">
						            		<input type="hidden" name="hidDiaDiem" />
						            		<div id="frmSearchProvider">
							            		Tên địa điểm
							            		<input type="text" name="txtProvider" />
							            		<input type="button" value="Tìm" id="btnSearchProvider" />
							            		<div id="searchResult"></div>
						            		</div>
						            	</div>
						            </li>
						            <li class="input">
						            	<label for="danhgia">Đánh Giá</label>                                    
						                <div style="display:inline-block;" id='blockDanhGia'>
						                	<input type="hidden" name="answerList" />
						                </div>                                                                        
						            </li>
						            <li class="input">
						            	<label>&nbsp;</label>
						        		<input type="submit" value="Xong Rùi" />    	
						            </li>
								</ul>
							</fieldset>							
						</form>                     
                    </div>  <!--end section -->
            	</div> <!-- end left -->        
                <div class="right">
        			<div class="aside">
                        <ul class="blockRightSide">	
                        	<h2 class="widgettitle">Đăng nhập</h2>
                            <li class="blockRight" id="blockSignIn"></li>
                            
                            <h2 class="widgettitle">Tìm kiếm</h2>
                            <li class="blockRight" id="blockSearch"></li>
                            
                            <h2 class="widgettitle">Thành viên</h2>                                            
                            <li class="blockRight" id="blockMembers"></li>
                            
                            <h2 class="widgettitle">Bài đăng mới nhất</h2>
                            <li class="blockRight" id="blockNewestPosts"></li>                          
                        </ul>
                    </div>        
                </div> <!--end right-->
			</div> <!--end container-->		
            
           <div id="footer" class="footer clearfix"></div>            
		</div>
	</body>
</html>